<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
      <el-form-item label="用户信息:" prop="member">
        <el-input
          size="mini"
          v-model="queryParams.member"
          placeholder="请输入邮箱/编号/姓名/昵称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="卡号:" prop="cardNo">
        <el-input
          size="mini"
          v-model="queryParams.cardNo"
          placeholder="请输入卡号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="卡模式:" prop="cardMode">
        <el-select v-model="queryParams.cardMode" placeholder="请选择卡模式" clearable size="mini" @change="getList">
          <el-option v-for="dict in dict.type['card_mode']"
                     :key="dict.value"
                     :label="dict.label"
                     :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="发卡商:" prop="network">
        <el-input
          size="mini"
          v-model="queryParams.network"
          placeholder="请输入发卡商"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="卡状态:" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择卡状态" clearable size="mini" @change="getList">
          <el-option v-for="dict in dict.type['interlace_card_status']"
                     :key="dict.value"
                     :label="dict.label"
                     :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="序号" type="index" align="center" min-width="5%"/>
      <el-table-column label="用户信息" align="center" prop="uid" key="uid">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="goMemberDetail(scope.row)"
          >
            用户信息
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="卡号" align="center" prop="cardNo" key="cardNo"/>
      <el-table-column label="发卡商" align="center" prop="network" key="network"/>
      <el-table-column label="卡模式" align="center" prop="cardMode" key="cardMode">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.card_mode" :value="scope.row.cardMode"/>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status" key="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.interlace_card_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="申请时间" align="center" prop="createTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="goBankDetail(scope.row)"
            v-hasPermi="['system:member:query']"
          >详情</el-button>
          <el-button
            v-if="scope.row.status !== 'Inactive'"
            type="danger"
            size="mini"
            plain
            @click="remove(scope.row)"
            v-hasPermi="['system:interlaceCard:delete']"
          >禁用</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <member-detail ref="member-detail"/>
    <bank-detail ref="bank-detail"/>
  </div>
</template>
<script>
import memberDetail from "@/views/triones/member/memberUser/memberDetail.vue";
import { pageList,remove } from '@/api/triones/interlaceCard'
import bankDetail from "@/views/triones/bankConnect/bankcards/bankDetail.vue";
export default {
  name: "index",
  components: {bankDetail, memberDetail },
  dicts: ['card_mode','interlace_card_status'],
  data() {
    return {
      loading: false,
      showSearch: true,
      dateRange: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        member: undefined,
        cardNo: undefined,
        cardMode: undefined,
        network: undefined,
        status: undefined
      },
      dataList: [],
      total: 0,
      open: false,
      bankList: [],
      cards: [],
      bankListQueryParams: {
        uid: undefined,
        type: undefined,
        cardStatus: undefined
      }
    }
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true;
      pageList(this.queryParams).then(res => {
        this.dataList = res.rows;
        this.total = res.total;
        this.loading = false;
      })
    },
    /** 检索 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 用户详情 */
    goMemberDetail(row) {
      this.$refs["member-detail"].show(row.uid);
    },
    goBankDetail(row) {
      this.$refs["bank-detail"].show(row.id);
    },
    /** 禁用该卡 */
    remove(row) {
      const id = row.id;
      this.$modal.confirm('注意：该操作不可逆转。是否确认禁用卡号为："' + row.cardNo + '"的卡片？').then(() => {
        this.loading = true;
        return remove(id);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("禁用成功");
      }).finally(() => {
        this.loading = false;
      });
    }
  }
}
</script>
<style scoped lang="scss">
.el-tooltip {
  overflow: hidden;
  display: -webkit-box;
  text-overflow: ellipsis;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  white-space: normal;
}
</style>
